/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/**
 *
 * @author pcsijbug
 */
public class BDConexFactory {
    
    private static BDConexFactory connectionFactory = null;
    private InitialContext ctx;
    private DataSource ds;


    private BDConexFactory() {
        try {
            ctx = new InitialContext();
            //datasource por defecto que esta configurado en el config.properties

           
          
                ds =(DataSource)ctx.lookup("jdbc/sample");
            
                System.out.println(":::CONECTO::::");
        } catch (Exception e) {
            System.out.println("BDConexFactory() " + e.getMessage());
            
        }
    }

    public Connection getConnection() throws SQLException {
        Connection conn = null;
        conn = ds.getConnection();
        return conn;
    }

    public static BDConexFactory getInstance() {
        if (connectionFactory == null) {
            connectionFactory = new BDConexFactory();
        }
        return connectionFactory;
    }
    
}
